package com.party.business.controller;


import com.party.business.domain.TComment;
import com.party.business.service.ITCommentService;
import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.core.page.TableDataInfo;
import com.party.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 评论模块
 */
@RestController
@RequestMapping("/business/comment")
public class TCommentController extends BaseController {
    @Autowired
    private ITCommentService tCommentService;

    /**
     * 查询评论列表分页
     */
    @GetMapping("/list")
    public TableDataInfo list(TComment tComment) {
        startPage();
        List<TComment> list = tCommentService.selectTCommentList(tComment);
        return getDataTable(list);
    }



    /**
     * 获取评论详细信息
     */
    //@RequiresPermissions("system:comment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tCommentService.getById(id));
    }

    /**
     * 新增评论
     */
    //@RequiresPermissions("system:comment:add")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TComment tComment) {
        return toAjax(tCommentService.save(tComment));
    }

    /**
     * 修改评论
     */
    //@RequiresPermissions("system:comment:edit")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TComment tComment) {
        return toAjax(tCommentService.updateById(tComment));
    }

    /**
     * 删除评论
     */
    //@RequiresPermissions("system:comment:remove")
    @Log(title = "评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tCommentService.removeByIds(Arrays.asList(ids)));
    }
}
